package com.itheima.controller;

import com.itheima.domain.pojo.Dept;
import com.itheima.domain.vo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * dept-部门管理
 * @author 上官徵羽
 * @version 1.0
 * @since 2025-08-15 11:24
 */
@RestController
@Slf4j
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /** 查询部门列表 */
    @GetMapping
    public Result getDeptList(){
        List<Dept> dept = deptService.getDeptList();
        return Result.success(dept);
    }

    /** 删除部门 */
    @DeleteMapping
    public Result deleteDept(Integer id){
        deptService.deleteDept(id);
        return Result.success();
    }

    /** 新增部门 */
    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        deptService.addDept(dept);
        return Result.success();
    }

    /** 根据id查询部门信息 */
    @GetMapping("{id}")
    public Result getDeptId(@PathVariable("id") Integer id){
        Dept dept = deptService.getDeptId(id);
        return Result.success(dept);
    }

    /** 修改部门信息 */
    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        deptService.updateDept(dept);
        return Result.success();
    }



}
